package leetcode;

import java.util.Stack;

public class MinStack {
    Stack<Integer> stack;
    Stack<Integer> minStack;
    public MinStack(){
        stack=new Stack<>();
        minStack=new Stack<>();
    }
    public void push(int val){
    stack.push(val);
    if(minStack.isEmpty()||val<=minStack.peek()){
        minStack.push(val);
    }
    }
    public void pop(){
    int val=stack.pop();
    if(minStack.peek()==val){
        minStack.pop();
    }
    }
    public int top(){
    return stack.peek();
    }
    public int getmin(){
        return minStack.peek();
    }
}
